import { render, createVNode } from 'vue'
import Confirm from './xtx-confirm.vue'

const div = document.createElement('div')
div.setAttribute('class', 'xtx-confirm')
document.body.appendChild(div)

export default ({ title, text }) => {
  return new Promise((resolve, reject) => {
    const resolvecallback = () => {
      render(null, div)
      resolve()
    }
    const rejectcallback = () => {
      render(null, div)
      reject(new Error('取消'))
    }
    const confirmvnode = createVNode(Confirm, {
      title,
      text,
      resolvecallback,
      rejectcallback
    })
    render(confirmvnode, div)
  })
}
